home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / TMEditor.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  27KB  |  1,068 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATKeyboard Version 4.0                    ** */
  4. /* **            Copright (C) 1992-1994 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* **                    Tastaturtabellen-Editor                    ** */
  8. /* **                                                               ** */
  9. /* ******************************************************************* */
  10.  
  11. #include "ATKeyboard.h"
  12.  
  13. EXTERN LONG                  KickstartVersion;
  14. EXTERN UBYTE                 TastenTabelle[256];
  15. EXTERN UBYTE                *HelpName;
  16. extern struct TextAttr       OpalFontDef;
  17. extern struct IntuiText      Trennlinie_Text;
  18. extern struct IntuiText      Wirklich_Text;
  19. extern struct Einstellungen  Einstellungen;
  20. extern struct KeyCodes      *KeyCodes;
  21. extern struct FileRequester *FileRequester;
  22. extern struct MenuItem       TM_Item[];
  23. struct KeyTab               *BackupKeys;
  24.  
  25. struct IntuiText TEdHilfe_Text=
  26. {
  27.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  28.  "Hilfe zum Editor",
  29. };
  30.  
  31. struct IntuiText TU_Text=
  32. {
  33.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  34.  "Rücknahme aller Aktionen",
  35. };
  36.  
  37. struct IntuiText Kopieren_Text=
  38. {
  39.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  40.  "Taste kopieren",
  41. };
  42.  
  43. struct IntuiText Tauschen_Text=
  44. {
  45.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  46.  "Tasten tauschen",
  47. };
  48.  
  49. struct IntuiText CodeTable_Text=
  50. {
  51.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  52.  "CodeTable-Datei",
  53. };
  54.  
  55. struct IntuiText Translator_Text=
  56. {
  57.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  58.  "Translator-Datei",
  59. };
  60.  
  61. struct IntuiText ML_Text=
  62. {
  63.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  64.  "Tastaturtabelle laden von",
  65. };
  66.  
  67. struct IntuiText MS_Text=
  68. {
  69.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  70.  "Tastaturtabelle sichern als",
  71. };
  72.  
  73. struct IntuiText TE_Text=
  74. {
  75.  AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
  76.  "Übernehmen und Beenden",
  77. };
  78.  
  79. struct MenuItem TE_Item=
  80. {
  81.  NULL,
  82.  5,30,300,10,
  83.  HIGHIMAGE|ITEMENABLED|ITEMTEXT|COMMSEQ,
  84.  0L,
  85.  &TE_Text,
  86.  &Wirklich_Text,
  87.  'Q',NULL
  88. };
  89.  
  90. struct MenuItem Trennlinie02_Item=
  91. {
  92.  &TE_Item,
  93.  5,20,300,10,
  94.  HIGHNONE|ITEMTEXT,
  95.  0L,
  96.  &Trennlinie_Text,
  97.  NULL,
  98.  0,NULL
  99. };
  100.  
  101. struct MenuItem CS_Item=
  102. {
  103.  NULL,
  104.  180,14,250,10,
  105.  HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT,
  106.  0L,
  107.  &CodeTable_Text,
  108.  NULL,
  109.  'R',NULL
  110. };
  111.  
  112. struct MenuItem TS_Item=
  113. {
  114.  &CS_Item,
  115.  180,4,250,10,
  116.  HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT,
  117.  0L,
  118.  &Translator_Text,
  119.  NULL,
  120.  'S',NULL
  121. };
  122.  
  123. struct MenuItem CL_Item=
  124. {
  125.  NULL,
  126.  180,14,250,10,
  127.  HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT,
  128.  0L,
  129.  &CodeTable_Text,
  130.  NULL,
  131.  'W',NULL
  132. };
  133.  
  134. struct MenuItem TL_Item=
  135. {
  136.  &CL_Item,
  137.  180,4,250,10,
  138.  HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT,
  139.  0L,
  140.  &Translator_Text,
  141.  NULL,
  142.  'L',NULL
  143. };
  144.  
  145. struct MenuItem MS_Item=
  146. {
  147.  &Trennlinie02_Item,
  148.  5,10,300,10,
  149.  HIGHCOMP|ITEMENABLED|ITEMTEXT,
  150.  0L,
  151.  &MS_Text,
  152.  NULL,
  153.  0,&TS_Item
  154. };
  155.  
  156. struct MenuItem ML_Item=
  157. {
  158.  &MS_Item,
  159.  5,0,300,10,
  160.  HIGHCOMP|ITEMENABLED|ITEMTEXT,
  161.  0L,
  162.  &ML_Text,
  163.  NULL,
  164.  0,&TL_Item
  165. };
  166.  
  167. struct MenuItem Swap_Item=
  168. {
  169.  NULL,
  170.  5,20,300,10,
  171.  HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
  172.  0L,
  173.  &Tauschen_Text,
  174.  NULL,
  175.  'T',NULL
  176. };
  177.  
  178. struct MenuItem Copy_Item=
  179. {
  180.  &Swap_Item,
  181.  5,10,300,10,
  182.  HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
  183.  0L,
  184.  &Kopieren_Text,
  185.  NULL,
  186.  'C',NULL
  187. };
  188.  
  189. struct MenuItem TU_Item=
  190. {
  191.  &Copy_Item,
  192.  5,0,300,10,
  193.  HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
  194.  0L,
  195.  &TU_Text,
  196.  NULL,
  197.  'X',NULL
  198. };
  199.  
  200. struct MenuItem TEdHilfe_Item=
  201. {
  202.  NULL,
  203.  -235,0,300,10,
  204.  HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
  205.  0L,
  206.  &TEdHilfe_Text,
  207.  NULL,
  208.  'H',NULL
  209. };
  210.  
  211. struct Menu THilfe_Menu=
  212. {
  213.  NULL,
  214.  560,0,70,10,
  215.  MENUENABLED,
  216.  "Hilfe",
  217.  &TEdHilfe_Item
  218. };
  219.  
  220. struct Menu TBearbeiten_Menu=
  221. {
  222.  &THilfe_Menu,
  223.  140,0,130,10,
  224.  MENUENABLED,
  225.  "Bearbeiten",
  226.  &TU_Item
  227. };
  228.  
  229. struct Menu TDatei_Menu=
  230. {
  231.  &TBearbeiten_Menu,
  232.  5,0,130,10,
  233.  MENUENABLED,
  234.  "Datei",
  235.  &ML_Item
  236. };
  237.  
  238. #define MENU_DATEI 0
  239. #define ITEM_LADEN 0
  240. #define ITEM_SICHERN 1
  241. #define SUBITEM_TRANSLATOR 0
  242. #define SUBITEM_CODETABLE 1
  243. #define ITEM_ENDE 3
  244. #define MENU_BEARBEITEN 1
  245. #define ITEM_UNDO 0
  246. #define ITEM_KOPIEREN 1
  247. #define ITEM_TAUSCHEN 2
  248. #define MENU_HILFE 2
  249. #define ITEM_HILFE 0
  250.  
  251. #define xITEMENABLED (0xffff-ITEMENABLED)
  252.  
  253. UBYTE Name[20];
  254. UBYTE pos;
  255.  
  256. struct InputEvent ie=
  257. {
  258.  NULL,IECLASS_RAWKEY,0,0,0
  259. };
  260.  
  261. struct RawName
  262. {
  263.  WORD   Select;
  264.  UBYTE *Name;
  265. };
  266.  
  267. struct RawName RawName[]={
  268.  0x45,"Escape",
  269.  0x50,"F1",
  270.  0x51,"F2",
  271.  0x52,"F3",
  272.  0x53,"F4",
  273.  0x54,"F5",
  274.  0x55,"F6",
  275.  0x56,"F7",
  276.  0x57,"F8",
  277.  0x58,"F9",
  278.  0x59,"F10",
  279.  0x46,"Del",
  280.  0x5f,"Help",
  281.  0x41,"Backspace",
  282.  0x66,"Amiga links",
  283.  0x67,"Amiga rechts",
  284.  0x64,"Alt links",
  285.  0x65,"Alt rechts",
  286.  0x60,"Shift links",
  287.  0x61,"Shift rechts",
  288.  0x63,"Control",
  289.  0x62,"Caps Lock",
  290.  0x40,"Space",
  291.  0x42,"Tab",
  292.  0x44,"Return",
  293.  0x43,"Enter",
  294.  0x4c,"Cursor auf",
  295.  0x4f,"Cursor ab",
  296.  0x4e,"Cursor rechts",
  297.  0x4d,"Cursor links",
  298.  0x5a,"Num Lock",
  299.  0x5b,"Scroll Lock",
  300.  0x5d,"Print Screen",
  301.  0x3d,"7/Home",
  302.  0x3e,"8/Cursor auf",
  303.  0x3f,"9/Seite auf",
  304.  0x2d,"4/Cursor links",
  305.  0x2e,"5",
  306.  0x2f,"6/Cursor rechts",
  307.  0x1d,"1/End",
  308.  0x1e,"2/Cursor ab",
  309.  0x1f,"3/Seite ab",
  310.  0x0f,"0/Insert",
  311.  0x3c,"./Del",
  312.  0x4a,"Ziffernblock: +",
  313.  0x5e,"Ziffernblock: -",
  314.  0x5c,"Ziffernblock: /",
  315.  0x0e,NULL,
  316.  0x1c,NULL,
  317.  0x2c,NULL,
  318.  0x3b,NULL,
  319.  -1,NULL
  320. };
  321.  
  322.  
  323. /* Sondertastenname ermitteln */
  324. BOOL GetRawName(select)
  325.  UBYTE         select;
  326. {
  327.  REGISTER WORD i;
  328.  
  329.  for(i=0;RawName[i].Select!=-1;i++)
  330.   {
  331.    if(RawName[i].Select==select)
  332.     {
  333.      if(RawName[i].Name!=NULL) sprintf(&Name,"<%s>",RawName[i].Name);
  334.      return(TRUE);
  335.     }
  336.   }
  337.  return(FALSE);
  338. }
  339.  
  340.  
  341. /* Tastenname ermitteln */
  342. UBYTE *GetName(select)
  343.  UBYTE select;
  344. {
  345.  UBYTE byte;
  346.  UBYTE anz;
  347.  BOOL  res;
  348.  
  349.  strcpy(&Name,"");
  350.  res=GetRawName(select);
  351.  if((res==FALSE)&&(select>=0x00)&&(select<0x40))
  352.   {
  353.    ie.ie_Code=select;
  354.    anz=RawKeyConvert(&ie,&byte,1L,NULL);
  355.    if(anz==1) sprintf(&Name,"<%c>",byte);
  356.   }
  357.  return(&Name);
  358. }
  359.  
  360.  
  361. /* Neue Tastenbelegung zeigen */
  362. VOID ShowKey(rp,st,val,sel)
  363.  struct RastPort *rp;
  364.  UBYTE            st,val,sel;
  365. {
  366.  UBYTE          str[32];
  367.  REGISTER UWORD x,y;
  368.  
  369.  x=st*12;
  370.  y=62+x;
  371.  SetAPen(rp,0);
  372.  RectFill(rp,20,54+x,345,66+x);
  373.  SelectStdFPen(rp);
  374.  
  375.  sprintf(&str,"$%02lx",sel);
  376.  WriteText(rp,20,y,&str);
  377.  WriteText(rp,60,y,"->");
  378.  sprintf(&str,"$%02lx",val);
  379.  WriteText(rp,90,y,&str);
  380.  sprintf(&str,"($%02lx)",val+BIT7);
  381.  WriteText(rp,130,y,&str);
  382.  WriteText(rp,200,y,GetName(sel));
  383. }
  384.  
  385.  
  386. /* Hex-Zeichen in Zahl wandeln */
  387. UBYTE GetHex(chr)
  388.  UBYTE chr;
  389. {
  390.  
  391.  if((chr>='0')&&(chr<='9')) return(chr-48);
  392.  return(chr-55);
  393. }
  394.  
  395.  
  396. /* Editorzeile anzeigen */
  397. VOID PrintS(win,select,value,upValue,phase)
  398.  struct Window *win;
  399.  UBYTE          select;
  400.  UBYTE          value;
  401.  UBYTE          upValue;
  402.  UBYTE          phase;
  403. {
  404.  UBYTE          str[75];
  405.  
  406.  switch(phase)
  407.   {
  408.    case 0:
  409.      sprintf(&str,"$%02lx -> $%02lx ($%02lx)     %s",select,value,upValue,GetName(select));
  410.     break;
  411.    case 1:
  412.      sprintf(&str,"$%02lx -> $%lx- ($--)     %s",select,value,GetName(select));
  413.     break;
  414.    case 2:
  415.      sprintf(&str,"Kopieren [$%02lx -> $%02lx ($%02lx)     %s]",select,value,upValue,GetName(select));
  416.     break;
  417.    case 3:
  418.      sprintf(&str,"Tauschen [$%02lx -> $%02lx ($%02lx)     %s]",select,value,upValue,GetName(select));
  419.     break;
  420.   }
  421.  
  422.  DrawMNTextBorder(win,90,38,350,12,&str);
  423. }
  424.  
  425.  
  426. /* Editor-Reset */
  427. VOID ResetEditor(rp)
  428.  struct RastPort *rp;
  429. {
  430.  REGISTER WORD i;
  431.  
  432.  for(i=0;i<8;i++)
  433.    ShowKey(rp,i,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+i],pos+i);
  434. }
  435.  
  436.  
  437. /* ASCII-Zeile schreiben */
  438. VOID AWrite(fh,tex)
  439.  struct FileHandle *fh;
  440.  UBYTE             *tex;
  441. {
  442.  Write(fh,tex,strlen(tex));
  443. }
  444.  
  445.  
  446. UBYTE *Logo[]=
  447. {
  448.  "***********************************************\n",
  449.  "****                                       ****\n",
  450.  "****    ATKeyboard 4.0 Translator File     ****\n"
  451. };
  452.  
  453.  
  454. /* Translator-Datei schreiben */
  455. VOID WriteTranslator(fh)
  456.  struct FileHandle *fh;
  457. {
  458.  REGISTER WORD      i;
  459.  UBYTE              buf[64];
  460.  
  461.  AWrite(fh,Logo[0]);
  462.  AWrite(fh,Logo[1]);
  463.  AWrite(fh,Logo[2]);
  464.  AWrite(fh,Logo[1]);
  465.  AWrite(fh,Logo[0]);
  466.  AWrite(fh,"\n\nPC    <- Amiga <- Taste\n-----------------------\n");
  467.  for(i=0;i<=0x7f;i++)
  468.   {
  469.    sprintf(&buf,"$%02lx   <- $%02lx   <- %s\n",
  470.            KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[i],
  471.            i,GetName(i));
  472.    AWrite(fh,&buf);
  473.   }
  474. }
  475.  
  476.  
  477. /* Zeile lesen */
  478. BOOL ReadLine(fh,tex)
  479.  struct FileHandle *fh;
  480.  UBYTE             *tex;
  481. {
  482.  REGISTER WORD      i,j,anz;
  483.  UBYTE              byte;
  484.  
  485.  anz=0;
  486.  for(i=0;i<79;i++)
  487.   {
  488.    j=Read(fh,&byte,1L);
  489.    if(j==0)
  490.     {
  491.      tex[anz]=0x00;
  492.      return(FALSE);
  493.     }
  494.    switch(byte)
  495.     {
  496.      case 13:
  497.      case 10:
  498.        tex[anz]=0x00;
  499.        return(TRUE);
  500.       break;
  501.      default:
  502.        tex[anz]=byte;
  503.        anz++;
  504.       break;
  505.     }
  506.   }
  507.  tex[79]=0x00;
  508.  return(TRUE);
  509. }
  510.  
  511.  
  512. /* Translator-Datei lesen */
  513. VOID ReadTranslator(win,fh,pos,select)
  514.  struct Window     *win;
  515.  struct FileHandle *fh;
  516.  UBYTE              pos;
  517.  UBYTE              select;
  518. {
  519.  REGISTER WORD      a,b,zeile;
  520.  REGISTER UBYTE     anz;
  521.  REGISTER BOOL      okay,res;
  522.  UBYTE              byte;
  523.  UBYTE              buf[80];
  524.  UBYTE              TBuffer[128];
  525.  UBYTE             *Titel;
  526.  
  527.  Titel=win->Title;
  528.  SetWindowTitles(win,"Lade Translator-Datei...",-1L);
  529.  okay=FALSE;
  530.  anz=0;
  531.  zeile=0;
  532.  while(okay==FALSE)
  533.   {
  534.    res=ReadLine(fh,&buf);
  535.    zeile++;
  536.    if(res==TRUE)
  537.     {
  538.      if(buf[0]=='$')
  539.       {
  540.        buf[1]=toupper(buf[1]);
  541.        buf[2]=toupper(buf[2]);
  542.        a=b=-1L;
  543.        if( ((buf[1]>='0')&&(buf[1]<='9')) || ((buf[1]>='A')&&(buf[1]<='F')) ) a=GetHex(buf[1]);
  544.        if( ((buf[2]>='0')&&(buf[2]<='9')) || ((buf[2]>='A')&&(buf[2]<='F')) ) b=GetHex(buf[2]);
  545.        if((a==-1L)||(b==-1L))
  546.         {
  547.          if(a==-1L) a=1; else a=2;
  548.          sprintf(&buf,"%ld, %ld. Zeichen.",zeile,a);
  549.          Requester("Formatfehler in Zeile",&buf,"Okay",NULL);
  550.          okay=TRUE;
  551.         }
  552.        TBuffer[anz]=(a*16)+b;
  553.        anz++;
  554.        if(anz==128) okay=TRUE;
  555.       }
  556.     }
  557.    else
  558.     {
  559.      okay=TRUE;
  560.     }
  561.   }
  562.  if(anz==128)
  563.   {
  564.    for(a=0;a<=127;a++)
  565.     {
  566.      if(TBuffer[a]>=BIT7) TBuffer[a]-=BIT7;
  567.      KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[a]=TBuffer[a];
  568.      KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[a+BIT7]=TBuffer[a]+BIT7;
  569.     }
  570.    ResetEditor(win->RPort);
  571.    PrintS(win,0,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[select],
  572.                 KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[select+BIT7],0);
  573.   }
  574.  else
  575.   {
  576.    sprintf(&buf,"%ld statt 128 Zeichen.",anz);
  577.    Requester("Die Translator-Datei enthält nur",&buf,"Okay",NULL);
  578.   }
  579.  SetWindowTitles(win,Titel,-1L);
  580. }
  581.  
  582.  
  583. /* Tasten-Test */
  584. VOID TastenTest()
  585. {
  586.  register struct Window       *win;
  587.  register struct IntuiMessage *msg;
  588.  REGISTER ULONG                Class;
  589.  REGISTER UWORD                Code,Qualifier,i;
  590.  REGISTER BOOL                 ende;
  591.  
  592.  ende=FALSE;
  593.  win=CreateStdWindow("Testen-Test  -> Bitte Eingaben machen <-",
  594.                      75,5,460,BorderHeight(),
  595.                      CLOSEWINDOW|RAWKEY|INACTIVEWINDOW,
  596.                      WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|ACTIVATE);
  597.  if(win!=NULL)
  598.   {
  599.    while(ende==FALSE)
  600.     {
  601.      WaitPort(win->UserPort);
  602.      msg=GetMsg(win->UserPort);
  603.      Class=msg->Class;
  604.      Code=msg->Code;
  605.      Qualifier=msg->Qualifier;
  606.      ReplyMsg(msg);
  607.      switch(Class)
  608.       {
  609.        case RAWKEY:
  610.          for(i=0;i<256;i++) TastenTabelle[i]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[i];
  611.          Taste(Code,Qualifier);
  612.         break;
  613.        case INACTIVEWINDOW:
  614.        case CLOSEWINDOW:
  615.          ende=TRUE;
  616.         break;
  617.       }
  618.     }
  619.    DeleteStdWindow(win);
  620.   }
  621. }
  622.  
  623.  
  624. /* Editor-Hauptprogramm */
  625. VOID TMEditor()
  626. {
  627.  register struct Gadget       *Gadget;
  628.  register struct Window       *win;
  629.  register struct IntuiMessage *msg;
  630.  register struct RastPort     *rp;
  631.  register struct FileHandle   *fh;
  632.  struct PropInfo              *PInfo;
  633.  struct Gadget                *PGadget;
  634.  REGISTER UBYTE               *k;
  635.  REGISTER ULONG                Class;
  636.  REGISTER UWORD                Code,ItemNum,MenuNum,SubItemNum;
  637.  REGISTER WORD                 i,j,id;
  638.  UBYTE                         Phase,UndoChar,copy;
  639.  BOOL                          ende,refresh,changed;
  640.  UBYTE                         Select;
  641.  UBYTE                         Value;
  642.  UBYTE                         STNum;
  643.  
  644.  BackupKeys=AllocMem(256,MEMF_CLEAR|MEMF_PUBLIC);
  645.  if(BackupKeys==NULL) return;
  646.  CopyMem(&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,BackupKeys,256);
  647.  Select=0;
  648.  Phase=0;
  649.  STNum=0;
  650.  Value=0;
  651.  copy=0;
  652.  changed=FALSE;
  653.  UndoChar=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[0];
  654.  pos=0;
  655.  
  656.  win=CreateStdWindow("ATKeyboard - Tastaturtabellen-Editor",
  657.                      75,25,460,156+BorderHeight(),
  658.                      GADGETUP|CLOSEWINDOW|VANILLAKEY|MENUPICK,
  659.                      WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|ACTIVATE|GIMMEZEROZERO);
  660.  if(win!=NULL)
  661.   {
  662.    10,40,340,10,
  663.    rp=win->RPort;
  664.    SetFont(rp,GetOpalFont());
  665.    CreateBoolGadget(win,10,5,210,12,"Einstellungen okay",10000);
  666.    CreateBoolGadget(win,230,5,210,12,"Einstellungen verwerfen",20000);
  667.    CreateBoolGadget(win,10,22,80,12,"Test",1000);
  668.    CreateBoolGadget(win,145,22,95,12,"Kopieren",2000);
  669.    CreateBoolGadget(win,245,22,95,12,"Tauschen",3000);
  670.    CreateBoolGadget(win,345,22,95,12,"Hilfe",4000);
  671.    for(i=0;i<8;i++)
  672.      CreateMinGadget(win,11,53+(i*12),358,12,i);
  673.    ResetEditor(rp);
  674.    PGadget=CreatePropGadget(win,375,53,65,98,0,0,0,512,500);
  675.    PInfo=PGadget->SpecialInfo;
  676.    DrawNBorder(win,10,53,360,98);
  677.    SelectStdFPen(rp);
  678.    WriteText(rp,20,48,"Auswahl:");
  679.    SetMenuStrip(win,&TDatei_Menu);
  680.    PrintS(win,0,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[0],
  681.                 KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[BIT7],
  682.                 0);
  683.    ende=FALSE;
  684.    while(ende==FALSE)
  685.     {
  686.      WaitPort(win->UserPort);
  687.      msg=GetMsg(win->UserPort);
  688.      Class=msg->Class;
  689.      Code=msg->Code;
  690.      Gadget=msg->IAddress;
  691.      ReplyMsg(msg);
  692.      switch(Class)
  693.       {
  694.        case VANILLAKEY:
  695.          changed=TRUE;
  696.          Code=toupper(Code);
  697.          refresh=FALSE;
  698.          if(((Code>='0')&&(Code<='9')) || ((Code>='A')&&(Code<='F')))
  699.           {
  700.            switch(Phase)
  701.             {
  702.              case 0:
  703.                Value=GetHex(Code);
  704.                PrintS(win,Select,Value,0,1);
  705.                Phase=1;
  706.               break;
  707.              case 1:
  708.                Value=(Value*16)+GetHex(Code);
  709.                if(Value>=BIT7) Value-=BIT7;
  710.                PrintS(win,Select,Value,Value+BIT7,0);
  711.                KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select]=Value;
  712.                KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7]=Value+BIT7;
  713.                Phase=0;
  714.                refresh=TRUE;
  715.               break;
  716.             }
  717.           }
  718.          else if((Code==13)&&(Phase==1))
  719.           {
  720.            PrintS(win,Select,Value,Value+BIT7,0);
  721.            KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select]=Value;
  722.            KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7]=Value+BIT7;
  723.            Phase=0;
  724.            refresh=TRUE;
  725.           }
  726.          else if(Code==27)
  727.           {
  728.            KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select]=UndoChar;
  729.            Phase=0;
  730.            PrintS(win,Select,UndoChar,UndoChar+BIT7,0);
  731.            Value=UndoChar;
  732.            refresh=TRUE;
  733.           }
  734.          if(refresh==TRUE)
  735.            ShowKey(rp,STNum,Value,Select);
  736.         break;
  737.        case MENUPICK:
  738.          MenuNum=MENUNUM(Code);
  739.          ItemNum=ITEMNUM(Code);
  740.          SubItemNum=SUBNUM(Code);
  741.          switch(MenuNum)
  742.           {
  743.            case MENU_DATEI:
  744.              switch(ItemNum)
  745.               {
  746.                case ITEM_SICHERN:
  747.                  switch(SubItemNum)
  748.                   {
  749.                    case SUBITEM_CODETABLE:
  750.                      if(FileRequester!=NULL)
  751.                       {
  752.                        k=FileReq("CodeTable-Datei sichern:","#?.codetable");
  753.                       }
  754.                      else
  755.                       {
  756.                        k=StringAbfrage(FALSE,"Name der CodeTable-Datei:","");
  757.                       }
  758.                      if((strcmp(k,"")))
  759.                       {
  760.                        fh=Open(k,MODE_NEWFILE);
  761.                        if(fh!=NULL)
  762.                         {
  763.                          Write(fh,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  764.                          Close(fh);
  765.                         }
  766.                        else
  767.                         {
  768.                          Requester("Konnte die CodeTable-Datei","nicht erstellen.","Okay",NULL);
  769.                         }
  770.                       }
  771.                     break;
  772.                    case SUBITEM_TRANSLATOR:
  773.                      if(FileRequester!=NULL)
  774.                       {
  775.                        k=FileReq("Translator-Datei sichern:","#?.translator");
  776.                       }
  777.                      else
  778.                       {
  779.                        k=StringAbfrage(FALSE,"Name der Translator-Datei:","");
  780.                       }
  781.                      if((strcmp(k,"")))
  782.                       {
  783.                        fh=Open(k,MODE_NEWFILE);
  784.                        if(fh!=NULL)
  785.                         {
  786.                          WriteTranslator(fh);
  787.                          Close(fh);
  788.                         }
  789.                        else
  790.                         {
  791.                          Requester("Konnte die Translator-Datei","nicht erstellen.","Okay",NULL);
  792.                         }
  793.                       }
  794.                     break;
  795.                   }
  796.                 break;
  797.                case ITEM_LADEN:
  798.                  switch(SubItemNum)
  799.                   {
  800.                    case SUBITEM_CODETABLE:
  801.                      if(FileRequester!=NULL)
  802.                       {
  803.                        k=FileReq("CodeTable-Datei laden:","#?.codetable");
  804.                       }
  805.                      else
  806.                       {
  807.                        k=StringAbfrage(FALSE,"Name der CodeTable-Datei:","");
  808.                       }
  809.                      if((strcmp(k,"")))
  810.                       {
  811.                        fh=Open(k,MODE_OLDFILE);
  812.                        if(fh!=NULL)
  813.                         {
  814.                          Read(fh,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  815.                          changed=TRUE;
  816.                          Close(fh);
  817.                         }
  818.                        else
  819.                         {
  820.                          Requester("Konnte die CodeTable-Datei","nicht laden.","Okay",NULL);
  821.                         }
  822.                       }
  823.                     break;
  824.                    case SUBITEM_TRANSLATOR:
  825.                      if(FileRequester!=NULL)
  826.                       {
  827.                        k=FileReq("Translator-Datei laden:","#?.translator");
  828.                       }
  829.                      else
  830.                       {
  831.                        k=StringAbfrage(FALSE,"Name der Translator-Datei:","");
  832.                       }
  833.                      if((strcmp(k,"")))
  834.                       {
  835.                        fh=Open(k,MODE_OLDFILE);
  836.                        if(fh!=NULL)
  837.                         {
  838.                          ReadTranslator(win,fh,pos,Select);
  839.                          changed=TRUE;
  840.                          Close(fh);
  841.                         }
  842.                        else
  843.                         {
  844.                          Requester("Konnte die Translator-Datei","nicht laden.","Okay",NULL);
  845.                         }
  846.                       }
  847.                     break;
  848.                   }
  849.                 break;
  850.                case ITEM_ENDE:
  851.                  ende=TRUE;
  852.                 break;
  853.               }
  854.             break;
  855.            case MENU_BEARBEITEN:
  856.              switch(ItemNum)
  857.               {
  858.                case ITEM_UNDO:
  859.                  CopyMem(BackupKeys,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  860.                  ResetEditor(rp);
  861.                  PrintS(win,0,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  862.                              KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],0);
  863.                 break;
  864.                case ITEM_KOPIEREN:
  865.                  copy=1; changed=TRUE;
  866.                  PrintS(win,Select,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  867.                                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],2);
  868.                 break;
  869.                case ITEM_TAUSCHEN:
  870.                  copy=2; changed=TRUE;
  871.                  PrintS(win,Select,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  872.                                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],3);
  873.                 break;
  874.               }
  875.             break;
  876.            case MENU_HILFE:
  877.              if(ItemNum==ITEM_HILFE) Help(HelpName,144);
  878.             break;
  879.           }
  880.         break;
  881.        case GADGETUP:
  882.          id=Gadget->GadgetID;
  883.          switch(id)
  884.           {
  885.            case 10000:
  886.              ende=TRUE;
  887.             break;
  888.            case 20000:
  889.              CopyMem(BackupKeys,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  890.              ende=TRUE;
  891.             break;
  892.            case 500:
  893.              pos=PInfo->VertPot/512;
  894.              if(pos>=120) pos=120;
  895.              ResetEditor(rp);
  896.             break;
  897.            case 1000:
  898.              ClearMenuStrip(win);
  899.              TastenTest();
  900.              SetMenuStrip(win,&TDatei_Menu);
  901.             break;
  902.            case 2000:
  903.              if(copy==1) { j=0; copy=0; } else { j=2; copy=1; }
  904.              PrintS(win,Select,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  905.                               KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],j);
  906.             break;
  907.            case 3000:
  908.              if(copy==2) { j=0; copy=0; } else { j=3; copy=2; }
  909.              PrintS(win,Select,KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  910.                               KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7],j);
  911.             break;
  912.            case 4000:
  913.              Help(HelpName,144);
  914.             break;
  915.            default:
  916.             if((id>=0)&&(id<=7))
  917.              {
  918.               switch(copy)
  919.                {
  920.                 case 1:
  921.                   copy=0;
  922.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+id]     =KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select];
  923.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+id+BIT7]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7];
  924.                   ResetEditor(rp);
  925.                  break;
  926.                 case 2:
  927.                   j=pos+id+BIT7;
  928.                   i=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select];
  929.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+id];
  930.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select+BIT7]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[j];
  931.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[pos+id]=i;
  932.                   KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[j]=i+BIT7;
  933.                   copy=0;
  934.                   ResetEditor(rp);
  935.                  break;
  936.                 default:
  937.                   Select=pos+id;
  938.                   Phase=0;
  939.                   STNum=id;
  940.                  break;
  941.                }
  942.               UndoChar=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[Select],
  943.               PrintS(win,Select,UndoChar,UndoChar+BIT7,0);
  944.              }
  945.           }
  946.         break;
  947.        case CLOSEWINDOW:
  948.          if(changed==TRUE)
  949.           {
  950.            ende=UsePrefs();
  951.            if(ende==FALSE)
  952.             {
  953.              CopyMem(BackupKeys,&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys,256);
  954.             }
  955.           }
  956.          ende=TRUE;
  957.         break;
  958.       }
  959.     }
  960.    ClearMenuStrip(win);
  961.    DeleteStdWindow(win);
  962.    for(i=0;i<256;i++) TastenTabelle[i]=KeyCodes->KeyTab[Einstellungen.Tastaturmodus].Keys[i];
  963.   }
  964.  FreeMem(BackupKeys,256);
  965. }
  966.  
  967.  
  968. /* Modusname ändern/Modus (de)aktivieren */
  969. VOID TMOnOff()
  970. {
  971.  REGISTER ULONG                Class;
  972.  REGISTER BOOL                 bool,neu,changed;
  973.  REGISTER WORD                 i,j;
  974.  UBYTE                        *Name[8];
  975.  struct Gadget                *OnOff_Gadget[7];
  976.  register struct Gadget       *g;
  977.  register struct Window       *win;
  978.  register struct IntuiMessage *msg;
  979.  
  980.  win=CreateStdWindow("ATKeyboard - Tastaturmodus (de)aktivieren",
  981.                      75,20,465,153+BorderHeight(),CLOSEWINDOW|GADGETUP|VANILLAKEY,
  982.                      WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE|GIMMEZEROZERO);
  983.  if(win!=NULL)
  984.   {
  985.    SetFont(win->RPort,GetOpalFont());
  986.    CreateBoolGadget(win,10,5,210,12,"Einstellungen okay",1000);
  987.    CreateBoolGadget(win,230,5,210,12,"Einstellungen verwerfen",2000);
  988.    CreateBoolGadget(win,10,24,100,12,"Hilfe",4000);
  989.    for(i=43,j=0;j<7;i+=15,j++)
  990.     {
  991.      if(KeyCodes->KeyTab[j+1].Valid)
  992.       {
  993.        OnOff_Gadget[j]=CreateSToggleGadget(win,10,i,100,12,"Aktiv",j);
  994.       }
  995.      else
  996.       {
  997.        OnOff_Gadget[j]=CreateNToggleGadget(win,10,i,100,12,"Aktiv",j);
  998.       }
  999.     }
  1000.    for(i=24,j=0;j<8;i+=15,j++)
  1001.     {
  1002.      Name[j]=CreateStringGadget(win,130,i,310,12,&KeyCodes->KeyTab[j].Name[2],28,100);
  1003.      if(j==0) i+=4;
  1004.    }
  1005.    bool=neu=changed=FALSE;
  1006.    while(bool==FALSE)
  1007.     {
  1008.      WaitPort(win->UserPort);
  1009.      msg=GetMsg(win->UserPort);
  1010.      Class=msg->Class;
  1011.      j=msg->Code;
  1012.      g=msg->IAddress;
  1013.      switch(Class)
  1014.       {
  1015.        case CLOSEWINDOW:
  1016.          bool=TRUE;
  1017.          if(changed==TRUE) neu=UsePrefs();
  1018.         break;
  1019.        case GADGETUP:
  1020.          switch(g->GadgetID)
  1021.           {
  1022.            case 4000:
  1023.              Help(HelpName,145);
  1024.             break;
  1025.            case 1000:
  1026.              neu=TRUE; bool=TRUE;
  1027.             break;
  1028.            case 2000:
  1029.              bool=TRUE;
  1030.             break;
  1031.            default:
  1032.              changed=TRUE;
  1033.             break;
  1034.           }
  1035.         break;
  1036.        case VANILLAKEY:
  1037.          if(j==13) bool=TRUE;
  1038.         break;
  1039.       }
  1040.      ReplyMsg(msg);
  1041.     }
  1042.    DeleteStdWindow(win);
  1043.    if(neu==TRUE)
  1044.     {
  1045.      for(i=0;i<=6;i++)
  1046.       {
  1047.        if(OnOff_Gadget[i]->Flags & SELECTED)
  1048.         {
  1049.          TM_Item[i+1].Flags |= ITEMENABLED;
  1050.          KeyCodes->KeyTab[i+1].Valid=1;
  1051.         }
  1052.        else
  1053.         {
  1054.          TM_Item[i+1].Flags &= xITEMENABLED;
  1055.          KeyCodes->KeyTab[i+1].Valid=0;
  1056.         }
  1057.       }
  1058.      for(i=0;i<=7;i++)
  1059.       {
  1060.        strcpy(&KeyCodes->KeyTab[i].Name,"  ");
  1061.        strcpy(&KeyCodes->KeyTab[i].Name[2],Name[i]);
  1062.       }
  1063.      NeuerModus(Einstellungen.Tastaturmodus,FALSE);
  1064.     }
  1065.   }
  1066. }
  1067.  
  1068.